package components {
	import beans.HireBean;
	import components.MessageItem;
	
	import mx.containers.VBox;
	import mx.events.FlexEvent;

	public class FullViewPanel extends VBox {

        //------------------------------------------------------------
        //
        // variables
        //
        //------------------------------------------------------------
        
        /**
         * the HireBean object
         */
        private var _hireInfo:HireBean;
        
        //------------------------------------------------------------
        //
        // mehtods
        //
        //------------------------------------------------------------
        
        /**
         * add a FullViewItem item, and the content will be bound with assigned control
         * @param label label of the item
         * @param content content of the item
         * @param host the object that hosts the property or property chain to be watched
         * @param chain a value specifying the property or chain to be watched
         * @param editable determite the content is editable or not
         */
        public function setItem(label:String, content:String,
        						host:Object = null, chain:String = null,
								editable:Boolean = false,
								multiLine:Boolean = false):void {
			removeAllChildren();
			
        	var item:FullViewItem = new FullViewItem(label, content,
													 host, chain,
													 editable, multiLine);
        	addChild(item);
        }
        
        /**
         * add three FullViewItem items for each property of HireInfo object
         * @param hireInfo data source object
         * @param editable determite each property is editable or not
         */
        public function setHireInfo(hireInfo:HireBean, editable:Boolean = false):void {
        	removeAllChildren();
        	
        	if (!hireInfo) {
        		_hireInfo = new HireBean(null);
        	} else {
        		_hireInfo = hireInfo;
        	}
        	
        	var specItem:FullViewItem =
				new FullViewItem("所需专业", _hireInfo.speciality,
								 _hireInfo, "speciality",
								 editable, false);
			
			var countItem:FullViewItem =
				new FullViewItem("招聘人数", _hireInfo.count.toString(),
								 _hireInfo, "count",
								 editable, false);
			
			var conditionItem:FullViewItem =
				new FullViewItem("基本要求", _hireInfo.condition,
								 _hireInfo, "condition",
								 editable, true);
			
			addChild(specItem);
			addChild(countItem);
			addChild(conditionItem);
        }
        
        /**
         * add a MessageItem
         * @param mode the mode of message display
         */
        public function setMessageItem(mode:String, message:String = null):void {
        	removeAllChildren();
        	
        	var msgItem:MessageItem = new MessageItem(mode, message);
        	addChild(msgItem);
        }
        
        /**
         * get the HireBean object which be inputed
         */
        public function getHireInfo():HireBean {
        	return _hireInfo;
        }
        
        //------------------------------------------------------------
        //
        // constructor
        //
        //------------------------------------------------------------

		public function FullViewPanel() {
			super();
			
			minHeight = 100;
			horizontalScrollPolicy = "off";
			
			addEventListener(FlexEvent.CREATION_COMPLETE, onCreationComplete);
		}
		
		//------------------------------------------------------------
        //
        // event handlers
        //
        //------------------------------------------------------------
		
		private function onCreationComplete(e:FlexEvent):void {
			setMessageItem(MessageItem.INIT);
		}
	}
}